
import r from '../helper/config.js';
import md5 from 'js-md5';
export function request(config={}){
	let {baseUrl,pid,key} = r
	let {
		url,
		method="GET",
		params={}
	} = config
	url = baseUrl + url
	const timestamp = parseInt(new Date().getTime() / 1000);
	const {osName} = uni.getSystemInfoSync();
	//固定传参
	const data = {
		token:uni.getStorageSync('token'),
		pid,
		sign:md5(key + timestamp),
		timestamp,
		ios:0,
		// ios:osName === 'ios' ? 1 : 0,
		cid:uni.getStorageSync('cid') || 0,
		sid:uni.getStorageSync('sid') || 0,
		...params
	}
	return new Promise((resolve,reject)=>{
		uni.request({
			url,
			method,
			data,
			header:{},
			success:res=>{
				if(res.data.code === 0 || res.data.status === 0){
					resolve(res.data)
				}else{
					uni.showToast({
						title:res.data.msg,
						icon:"none"
					})
					console.log('res.data: ',res.data);
					reject(res.data)
				}
			},
			fail:err=>{
				reject(err)
			}
		})
	})
}